home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
bipl.zip
/
PROCS.ZIP
/
TBLSET.ICN
< prev
next >
Wrap
Text File
|
1992-09-28
|
2KB
|
69 lines
############################################################################
#
# File: tblset.icn
#
# Subject: Procedures for set-theoretic table manipulation
#
# Author: Alan Beale
#
# Date: March 31, 1990
#
###########################################################################
#
# These procedures are defined:
#
# pairset(t) Convert the table t to an equivalent set of ordered pairs
#
# domain(t) Return the domain of the function defined by the table t
#
# range(t) Return the range of the function defined by the table t
#
# inverse(t) Return the functional inverse of the function defined
# by the table t
#
# inverse(t,[]) Return the relational inverse of the function defined
# by the table t.
#
# inverse(t, set([])) The same as the previous, except that each
# table member is a set rather than a list.
#
############################################################################
procedure pairset(Table)
return set(sort(Table))
end
procedure domain(Table)
local dom
dom := set([])
every insert(dom, key(Table))
return dom
end
procedure range(Table)
local ran
ran := set([])
every insert(ran, !Table)
return ran
end
procedure inverse(Table, Default)
local inv, delem, relem
inv := table(Default)
every delem := key(Table) do {
if type(Default) == "list" then
if member(inv, relem := Table[delem]) then
put(inv[relem], delem)
else inv[relem] := [delem]
else if type(Default) == "set" then
if member(inv, relem := Table[delem]) then
insert(inv[relem], delem)
else inv[relem] := set([delem])
else inv[Table[delem]] := delem
}
return inv
end